package _3_builder

type Pizza struct {
	Tomato  int //番茄
	Chili   int //辣椒
	Flour   int //面粉
	Size    int //尺寸
	Beef    int //牛肉
	Chicken int //鸡肉
}

var (
	defaultTomato  = 10
	defaultChili   = 10
	defaultFlour   = 10
	defaultSize    = 6
	defaultBeef    = 2
	defaultChicken = 0
)

type PizzaBuilder struct {
	tomato  int //番茄
	chili   int //辣椒
	flour   int //面粉
	size    int //尺寸
	beef    int //牛肉
	chicken int //鸡肉
}

func (p *PizzaBuilder) withTomato(tomato int) *PizzaBuilder {
	p.tomato = tomato
	return p
}
func (p *PizzaBuilder) withChili(chili int) *PizzaBuilder {
	p.chili = chili
	return p
}
func (p *PizzaBuilder) withFlour(flour int) *PizzaBuilder {
	p.flour = flour
	return p
}
func (p *PizzaBuilder) withSize(size int) *PizzaBuilder {
	p.size = size
	return p
}

func (p *PizzaBuilder) withBeef(beef int) *PizzaBuilder {
	p.beef = beef
	return p
}
func (p *PizzaBuilder) withChicken(chicken int) *PizzaBuilder {
	p.chicken = chicken
	return p
}

func (p *PizzaBuilder) build() (*Pizza, error) {
	pizza := &Pizza{}

	if p.tomato == 0 {
		pizza.Tomato = defaultTomato
	}

	if p.chili == 0 {
		pizza.Chili = defaultChili
	}

	if p.flour == 0 {
		pizza.Flour = defaultFlour
	}

	if p.size == 0 {
		pizza.Size = defaultSize
	}

	if p.beef == 0 {
		pizza.Beef = defaultBeef
	}

	if p.chicken == 0 {
		pizza.Chicken = defaultChicken
	}

	return pizza, nil

}
